<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>字符串refs基本</title>
  </head>
  <body>
    <div id="test"></div>
    <!-- 引入react核心库  优先 -->
    <script type="text/javascript" src="../js/react.development.js"></script>
    <!-- 引入react-dom用于支持react操作DOM，依赖react核心库 -->
    <script
      type="text/javascript"
      src="../js/react-dom.development.js"
    ></script>
    <!-- 引入babel，用于将jsx转换为js -->
    <script type="text/javascript" src="../js//babel.min.js"></script>
    <script type="text/babel">
      class Demo extends React.Component {
        handler = () => {
          alert(this.refs.leftInput.value);
          //获取左侧输入框的值，赋值给右侧输入框
        };
        handlerRight = () => {
          const { rightInput } = this.refs;
          alert(rightInput.value);
        };
        //注意：这里的refs加引号，都是字符串形式的！！！！！！
        //现在已经不推荐这种字符串的形式了！！！！！！！！！
        //字符串形式存在效率问题
        render() {
          return (
            <div>
              <input ref="leftInput" type="text" placeholder="左侧输入" />
              &nbsp;&nbsp;
              <button onClick={this.handler}>左侧输入</button>&nbsp;&nbsp;
              <input
                ref="rightInput"
                onBlur={this.handlerRight}
                type="text"
                placeholder="右侧输入"
              />
            </div>
          );
        }
      }

      ReactDOM.render(<Demo />, document.getElementById("test"));
    </script>
  </body>
</html>
